{% extends 'base.html' %}

{% load staticfiles %}

{% block title %}社区-学厨网{% endblock %}
{% block content %}
    <div class="container" style="margin-top: 70px;">
        <ol class="breadcrumb">
            <li><a href="{% url 'index' %}">首页</a></li>
            <li class="active">社区</li>
        </ol>
    </div>
    <div class="container">
        <!-- Example row of columns -->
        <div class="col-lg-8">

            <div class="page-header">
                <h2>{{ topic.title }}</h2>
            </div>

            <div class="media">
                <div class="media-left">
                    <a href="{% url 'cookbook:user_menu' topic.user_id %}">
                        <img class="img-circle" data-src="holder.js/64x64" alt="64x64"
                             src="{{ MEDIA_URL }}{{ topic.user.image }}"
                             data-holder-rendered="true" style="width: 64px; height: 64px;">
                    </a>
                </div>
                <div class="media-body">
                    <p style="margin-bottom: 10px;"><a
                            href="{% url 'cookbook:user_menu' topic.user_id %}">{{ topic.user }}</a></p>

                    {{ topic.content | safe }}
                    <div class="clearfix" style="margin-top: 20px;">
                        <div class="pull-left">
                            <span><span class="glyphicon glyphicon-time"
                                        aria-hidden="true"></span>&nbsp;{{ topic.add_time }}</span>
                        </div>

                    </div>

                </div>
            </div>
            {% for topic_reply in topic_replys.object_list %}
                <div class="media" style="margin-bottom: 20px;">
                    <div class="media-left">
                        <a href="#">
                            <img class="img-circle" data-src="holder.js/64x64" alt="64x64"
                                 src="{{ MEDIA_URL }}{{ topic_reply.user.image }}"
                                 data-holder-rendered="true" style="width: 64px; height: 64px;">
                        </a>
                    </div>
                    <div class="media-body">
                        <p style="margin-bottom: 10px;"><a target="_blank" href="">{{ topic_reply.user }}</a></p>

                        {{ topic_reply.content | safe }}
                        <div class="clearfix" style="margin-top: 20px;">
                            <div class="pull-left">
                            <span><span class="glyphicon glyphicon-time"
                                        aria-hidden="true"></span>&nbsp;{{ topic_reply.add_time }}</span>
                            </div>

                        </div>

                    </div>
                </div>
            {% endfor %}


            <!---分页--->
            <div class="pageturn" style="text-align: center">
                <ul class="pagelist">
                    <div class="pagination">
                        {% if topic_replys.has_previous %}
                            <li class="long"><a href="?{{ topic_replys.previous_page_number.querystring }}"
                                                class="page">上一页</a></li>
                        {% endif %}
                        {% for page in topic_replys.pages %}
                            {% if page %}
                                {% ifequal page topic_replys.number %}
                                    <li class="active"><a href="?{{ page.querystring }}">{{ page }}</a></li>
                                {% else %}
                                    <li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
                                {% endifequal %}
                            {% else %}
                                <li class="none"><a href="">...</a></li>
                            {% endif %}
                        {% endfor %}
                        {% if topic_replys.has_next %}
                            <li class="long"><a href="?{{ topic_replys.next_page_number.querystring }}">下一页</a></li>
                        {% endif %}
                    </div>
                </ul>
            </div>

            <!---发帖表单--->
            <form action="{% url 'community:community_detail' topic.id %}" method="post" id="posting"
                  style="margin-bottom: 10px;">
                <div class="form-group">
                    <label for="name"><span class="glyphicon glyphicon-pencil"
                                            aria-hidden="true"></span>&nbsp;发表回复</label>
                </div>
                {% if user.is_authenticated %}
                    <div class="form-group" style="margin-left: 1px;">
                        {{ topic_reply_form.content }}
                    </div>
                {% else %}
                    <div class="form-group" style="margin-left: 1px;">
                        <textarea class="form-control" rows="12"></textarea>
                    </div>
                {% endif %}
                {% csrf_token %}
                <button type="submit" class="btn btn-primary">发&nbsp;表</button>
            </form>


        </div>
        <div class="col-lg-4">
            <div>
                {% for ad in ad_image %}
                    <a href="{{ ad.url }}"><img class="img-responsive center-block"
                                                src="{{ MEDIA_URL }}{{ ad.image }}" alt="..."></a>
                {% endfor %}
            </div>
            <div class="page-header">
                <h3>热门话题</h3>
            </div>
            <div>
                {% for hot_topic in hot_topics %}
                    <a href="{% url 'community:community_detail' hot_topic.id %}"
                       class="list-group-item ">{{ hot_topic.title }}</a>
                {% endfor %}
            </div>

        </div>

    </div> <!-- /container -->
    <script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
    <script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
{% endblock %}